home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / VGX / blob / texture.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.0 KB  |  122 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #ifdef STAPUFT
  18.  
  19. #include <gl.h>
  20.  
  21. extern unsigned long * readImageRGB(char *, int *, int *);
  22.  
  23. static float texture_def0[] = { TX_NULL };
  24. static float texture_def1[] = { TX_MINFILTER, TX_MIPMAP_POINT, 
  25.                    TX_MAGFILTER, TX_POINT, 
  26.                    TX_NULL };
  27. static float texture_def2[] = { TX_MINFILTER, TX_MIPMAP_BILINEAR, 
  28.                    TX_MAGFILTER, TX_BILINEAR, 
  29.                    TX_NULL };
  30. static float texture_def3[] = { TX_MINFILTER, TX_BILINEAR, 
  31.                    TX_MAGFILTER, TX_BILINEAR, 
  32.                    TX_NULL };
  33. static float texture_def4[] = { TX_MINFILTER, TX_MIPMAP_LINEAR, 
  34.                    TX_MAGFILTER, TX_BILINEAR, 
  35.                    TX_NULL };
  36.  
  37. bind_texture(name, n, type) 
  38. char *name;
  39. int n;
  40. int type;
  41.     static float texture_env[] = { TV_MODULATE, TV_NULL };
  42.     static int     init = 1;
  43.  
  44.     int        width, height;
  45.     unsigned long    *image;
  46.  
  47.     int     i;
  48.  
  49.     image = readImageRGB(name,&width,&height);
  50.  
  51.     switch(type) {
  52.     case 0:
  53.         texdef2d(n, 4, width, height, image, 0, texture_def0 );
  54.         break;
  55.     case 1:
  56.         texdef2d(n, 4, width, height, image, 0, texture_def1 );
  57.         break;
  58.     case 2:
  59.         texdef2d(n, 4, width, height, image, 0, texture_def2 );
  60.         break;
  61.     case 3:
  62.         texdef2d(n, 4, width, height, image, 0, texture_def3 );
  63.         break;
  64.     case 4:
  65.         texdef2d(n, 4, width, height, image, 0, texture_def4 );
  66.         break;
  67.     }
  68.  
  69.     if (init) {
  70.     init = 0;
  71.  
  72.     tevdef(1, 0, texture_env); 
  73. /*    tevdef(0, 1, 0); */
  74.  
  75.     tevbind(TV_ENV0, 1);
  76.     }
  77. }
  78.  
  79. static int backixsize, backiysize;
  80. static unsigned long *backimgdat;
  81.  
  82. static float identity[4][4] = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};
  83.  
  84.  
  85. drawback(name)
  86. char *name;
  87. {
  88.     static unsigned long * backimgdat;
  89.     static float coord[4][2] = {{0,0},{0,1},{1,1},{1,0}}; 
  90.  
  91.     if(!backimgdat) {
  92.     int    width, height;
  93.  
  94.         backimgdat = readImageRGB(name,&width,&height);
  95.         texdef2d(10, 4, width, height, backimgdat, 0, texture_def0 );
  96.     }
  97.     ortho2(0.0,1.0,0.0,1.0);
  98.     pushmatrix();
  99.     loadmatrix(identity);
  100.  
  101.     texbind(TX_TEXTURE_0, 10);
  102.  
  103.     cpack(-1);
  104.     bgnpolygon();
  105.     t2f(coord[0]);
  106.     v2f(coord[0]);
  107.     t2f(coord[1]);
  108.     v2f(coord[1]);
  109.     t2f(coord[2]);
  110.     v2f(coord[2]);
  111.     t2f(coord[3]);
  112.     v2f(coord[3]);
  113.     endpolygon();
  114.  
  115.     texbind(TX_TEXTURE_0, 0);
  116.  
  117.     popmatrix();
  118. }
  119.  
  120. #endif STAPUFT
  121.